package com.knife.bbs.domain;

import java.util.Date;
import java.util.List;

import com.knife.dbo.EasyJDB;
import com.knife.dbo.IObject;

public class WebMessage implements IObject {

	public static final int NORMAL = 0;

	public static final int SENDDEL = 1;

	public static final int REVDEL = 5;

	public static final int NORMALMSG = 0;

	public static final int SYSTEMMSG = 1;

	public static final int SYSTEMSENDMSG = 5;

	public static final int READ = 1;

	public static final int UNREAD = 0;

	public static final String WELCOMEMSG = "welcome";

	public static final String FRIENDREQMSG = "friend";

	public static final String ACKMSG = "ack";

	private String cid;

	private String fromname;

	private String toname;

	private String title;

	private String message;

	private Date senddate;

	private Date readdate;

	private Integer status;

	private Integer type;

	private Integer isread;

	private Integer ack;

	public Integer getAck() {
		return ack;
	}

	public void setAck(Integer ack) {
		ack = ack;
	}

	public Integer getIsread() {
		return isread;
	}

	public void setIsread(Integer isRead) {
		this.isread = isRead;
	}

	public static WebMessage read(String cid) {
		return (WebMessage) EasyJDB.getInstance().read(WebMessage.class,
				"cid='" + cid + "'");
	}

	public static List query(String scope) {
		return EasyJDB.getInstance().query(WebMessage.class, scope);
	}

	public static Number UnReadNum(String toname) {
		EasyJDB db = EasyJDB.getInstance();
		Number num = (Number) db
				.uniqueResult("select count(*) from webmessage where toname='"
						+ toname + "' and isread=" + UNREAD
						+ " and status in (" + NORMAL + " , " + SENDDEL
						+ ") and type in (" + NORMALMSG + " , " + SYSTEMSENDMSG
						+ ")");
		return num;
	}

	public boolean save() {
		return EasyJDB.getInstance().add(this);
	}

	public boolean del() {
		return EasyJDB.getInstance().del(this);
	}

	public boolean update() {
		return EasyJDB.getInstance().update(this);
	}

	public String getCid() {
		return cid;
	}

	public void setCid(String cid) {
		this.cid = cid;
	}

	public String getFromname() {
		return fromname;
	}

	public void setFromname(String fromname) {
		this.fromname = fromname;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Date getReaddate() {
		return readdate;
	}

	public void setReaddate(Date readdate) {
		this.readdate = readdate;
	}

	public Date getSenddate() {
		return senddate;
	}

	public void setSenddate(Date senddate) {
		this.senddate = senddate;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getToname() {
		return toname;
	}

	public void setToname(String toname) {
		this.toname = toname;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public WebMessage() {
		super();
		// TODO Auto-generated constructor stub
	}

	public String getTableName() {
		// TODO Auto-generated method stub
		return "webmessage";
	}

	public String getKeyField() {
		// TODO Auto-generated method stub
		return "cid";
	}

	public String getKeyGenerator() {
		// TODO Auto-generated method stub
		return "com.knife.dbo.IdGenerator";
	}

}
